
#include "rendering.h"

static PROPSHEETPAGE *ps;
	
static HWND hRPoints;		// hWindow for the points
static HWND hRLines;		// hWindow for the lines
static HWND hRFilled;		// hWindow for the filled
static HWND hAntiAlias;		// Checkbox for antialiasing
static HWND hPtSize;		// Point size edit box
static HWND hPtStatic;		// Text for the point size
static HWND hPtBox;			// The point box

	// enable or disable the point box
void AblePointBox (BOOL state)
{
	EnableWindow (hAntiAlias, state);
	EnableWindow (hPtSize, state);
	EnableWindow (hPtStatic, state);
	EnableWindow (hPtBox, state);
}

BOOL APIENTRY RenderingConfigureDialog (HWND hDlg, UINT message,
		UINT wParam, LONG lParam)
{
	switch (message)
	{
	case WM_INITDIALOG:
		ps = (PROPSHEETPAGE*) lParam;

		polygonmode = polygonmode;
		pointsmooth = pointsmooth;
		pointsize = pointsize;

		return TRUE;
		break;

	case WM_NOTIFY:
		switch ( ( (NMHDR FAR *)lParam) -> code)
		{
		case PSN_SETACTIVE:
				// get the HWND for the dialog elements
			hRPoints = GetDlgItem (hDlg, IDC_RPOINTS);
			hRLines = GetDlgItem (hDlg, IDC_RLINES);
			hRFilled = GetDlgItem (hDlg, IDC_RFILLED);
			hAntiAlias = GetDlgItem (hDlg, IDC_ANTIALIAS);
			hPtSize = GetDlgItem (hDlg, IDC_PSIZE);
			hPtStatic = GetDlgItem (hDlg, IDC_PTSTATIC);
			hPtBox = GetDlgItem (hDlg, IDC_PTBOX);

				// Uncheck them all and then we will check the 
				// right one
			SendMessage (hRPoints, BM_SETCHECK, BST_UNCHECKED, 0);
			SendMessage (hRLines, BM_SETCHECK, BST_UNCHECKED, 0);
			SendMessage (hRFilled, BM_SETCHECK, BST_UNCHECKED, 0);
				// Disable the box first and then enable if point is selected
			AblePointBox (FALSE);

				// Check the right one
			if (polygonmode == 0)
			{
				SendMessage (hRPoints, BM_SETCHECK, BST_CHECKED, 0);
				AblePointBox (TRUE);
			}
			else if (polygonmode == 1)
				SendMessage (hRLines, BM_SETCHECK, BST_CHECKED, 0);
			else if (polygonmode == 2)
				SendMessage (hRFilled, BM_SETCHECK, BST_CHECKED, 0);

				// Put the tick mark about antialiasing
			if (pointsmooth)
				SendMessage (hAntiAlias, BM_SETCHECK, BST_CHECKED, 0);
			else
				SendMessage (hAntiAlias, BM_SETCHECK, BST_UNCHECKED, 0);

				// Stick the point size value in there
			SetDlgItemInt (hDlg, IDC_PSIZE, pointsize, FALSE);

			break;

		case PSN_APPLY:
			SaveRenderingSettings();
			break;

		case PSN_KILLACTIVE:
			break;
		}
		
		return TRUE;
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDC_RPOINTS:		// check for click on these checkboxes
			switch (HIWORD(wParam))
			{
			case BN_CLICKED:
				polygonmode = 0;
				AblePointBox (TRUE);
				break;
			}
			break;
		case IDC_RLINES:
			switch (HIWORD(wParam))
			{
			case BN_CLICKED:
				polygonmode = 1;
				AblePointBox (FALSE);
				break;
			}
			break;
		case IDC_RFILLED:
			switch (HIWORD(wParam))
			{
			case BN_CLICKED:
				polygonmode = 2;
				AblePointBox (FALSE);
				break;
			}
			break;
		case IDC_ANTIALIAS:
			switch (HIWORD(wParam))
			{
			case BN_CLICKED:
				pointsmooth = !pointsmooth;
				break;
			}
			break;
		case IDC_PSIZE:
			switch (HIWORD(wParam))
			{
			case EN_CHANGE:
				pointsize = GetDlgItemInt (hDlg, IDC_PSIZE, NULL, FALSE);
				break;
			}
			break;
		}
		return TRUE;
		break;
	}

	return FALSE;
}